package com.xindaoapp.happypet.db;

import java.util.List;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

import com.xindaoapp.happypet.bean.PostInfo3;
import com.xindaoapp.happypet.db.DaoMaster.DevOpenHelper;
import com.xindaoapp.happypet.db.model.PostDao;

public class DBManagerImpl implements IDBManager {
    private final SQLiteDatabase mSqLiteDatabase;
    private final DaoSession mDaoSession;

    private final PostDao mPostMessageDao;

    public DBManagerImpl(Context context) {
        DevOpenHelper helper = new DaoMaster.DevOpenHelper(context, "leepet-db", null);
        mSqLiteDatabase = helper.getWritableDatabase();
        DaoMaster daoMaster = new DaoMaster(mSqLiteDatabase);
        mDaoSession = daoMaster.newSession();
        mPostMessageDao = mDaoSession.getTagsDao();
    }

    @Override
    public void insertPost(PostInfo3 postInfo) {
        mPostMessageDao.insert(postInfo);
    }

    @Override
    public List<PostInfo3> loadPosts() {
        return mPostMessageDao.loadAll();
    }

    @Override
    public void deletePost(long postTime) {
        mPostMessageDao.delete(PostDao.Properties.POSTTIME.name + " = " + postTime);
    }

}
